﻿using System;
using System.Collections;

namespace Fawcett.Plugins.FSUIPCX
{
    public interface IOffset
    {
        string Name { get; set; }
        string Address { get; set; }
        string Type { get; set; }
        string Calculate { get; set; }

    }

    public class Offset : IOffset
    {
        private string _name ;
        public string Name { get{ return _name ; } 
                             set{ _name = value.Trim() ;} }
        public string Address { get; set; }
        public  string Type { get; set;}
        public string Calculate { get; set; }
    }

    public class OffsetCollection : CollectionBase
    {

        public OffsetCollection()
        {
        }


        public OffsetCollection(OffsetCollection value)
        {
            this.AddRange(value);
        }


        public OffsetCollection(IOffset[] value)
        {
            this.AddRange(value);
        }


        public IOffset this[int index]
        {
            get { return ((IOffset)(this.List[index])); }
        }

        public int Add(IOffset value)
        {
            return this.List.Add(value);
        }

        public void AddRange(IOffset[] value)
        {
            for (int i = 0; (i < value.Length); i = (i + 1))
            {
                this.Add(value[i]);
            }
        }

        public void AddRange(OffsetCollection value)
        {
            for (int i = 0; (i < value.Count); i = (i + 1))
            {
                this.Add((IOffset)value.List[i]);
            }
        }

        public bool Contains(IOffset value)
        {
            return this.List.Contains(value);
        }
        public void CopyTo(IOffset[] array, int index)
        {
            this.List.CopyTo(array, index);
        }

        public IOffset[] ToArray()
        {
            IOffset[] array = new IOffset[this.Count];
            this.CopyTo(array, 0);

            return array;
        }


        public int IndexOf(IOffset value)
        {
            return this.List.IndexOf(value);
        }

        public void Insert(int index, IOffset value)
        {
            List.Insert(index, value);
        }

        public void Remove(IOffset value)
        {
            List.Remove(value);
        }
        public new OffsetCollectionEnumerator GetEnumerator()
        {
            return new OffsetCollectionEnumerator(this);
        }

        public class OffsetCollectionEnumerator : IEnumerator
        {
            private IEnumerator _enumerator;
            private IEnumerable _temp;

            public OffsetCollectionEnumerator(OffsetCollection mappings)
            {
                _temp = ((IEnumerable)(mappings));
                _enumerator = _temp.GetEnumerator();
            }

            public IOffset Current
            {
                get { return ((IOffset)(_enumerator.Current)); }
            }

            object IEnumerator.Current
            {
                get { return _enumerator.Current; }
            }

            public bool MoveNext()
            {
                return _enumerator.MoveNext();
            }

            bool IEnumerator.MoveNext()
            {
                return _enumerator.MoveNext();
            }

            public void Reset()
            {
                _enumerator.Reset();
            }

            void IEnumerator.Reset()
            {
                _enumerator.Reset();
            }
        }
    }
}
